/************************************************************************/
/*	a super-lite class to load a static model							*/
/*	by GMKal
/************************************************************************/


#ifndef MODEL_H
#define MODEL_H


#include <vector>
#include "glmath.h"
using namespace glmath;
using namespace std;

typedef vector<int> IntVector;

class cModel;

bool ModelLoadFromAsciiMilkshapeStatic(const char* filename,cModel* pmodel);
bool ModelReloadTextures(cModel* pmodel);
bool ModelDraw(cModel* pmodel);

bool ModelReadMeshesMilkshapeAscii(FILE* pFile,cModel* pmodel,int numMeshes);
bool ModelReadMaterialsMilkshapeAscii(FILE* pFile,cModel* pmodel,int numMaterials);
void ModelClear(cModel *pmodel);

void ModelApplyMaterial(cModel *pmodel, int matIndex);
void ModelRender(cModel *pmodel);
void ModelRenderMesh(cModel *pmodel, int meshIndex);



//////////////////////////////////////////////////////////////////////////
// model without animation
class Model
{
public:
	//////////////////////////////////////////////////////////////////////////
	// define some structs here...


	//	Mesh
	struct Mesh
	{
		string	m_name;
		int		m_materialIndex;	// which material?
		int		m_numVertices;		// how many vertices
		IntVector m_vertexIndices;	// the
		int		m_numNormals;
		IntVector m_normalIndices;
		int		m_numTriangles;		// how many triangles
		IntVector m_triangleIndices;	// the triangles
	};

	// Material properties
	struct Material
	{
		char	m_name[32];
		GLfloat m_ambient[4];
		GLfloat m_diffuse[4];
		GLfloat m_specular[4];
		GLfloat m_emissive[4];
		GLfloat	m_shininess;
		GLfloat m_transparency;
		int		m_textureIndex;
		char	m_pTextureFilename[32];
		char	m_alphaTextureFilename[32];
	};

	//	Triangle structure
	struct Triangle
	{
		int			m_normalIndices[3];
		int			m_vertexIndices[3];
	};

	//	Vertex structure
	struct Vertex
	{
		char	 m_boneID;			// for skeletal animation
		Vector3 m_location;
		float	 m_s, m_t;			//texture coords
	};


		
	//	Meshes used
	//int m_numMeshes;
	//Mesh *m_pMeshes;
	vector<Mesh*> m_meshes;

	//	Materials used
	//int m_numMaterials;
	//Material *m_pMaterials;
	vector<Material*> m_materials;

	//	Triangles used
	//int m_numTriangles;
	//Triangle *m_pTriangles;
	vector<Triangle*> m_triangles;

	//	Vertices Used
	//int m_numVertices;
	//Vertex *m_pVertices;
	vector<Vertex*>	m_vertices;

	// normals used
	//int m_numNormals;
	//Vector3* m_pNormals;
	vector<Vector3*> m_normals;

	// textures
	vector<HTexture> m_textures;

	//vector<int,vector<int>> m_materialMeshes;	// associate each material with 
												// all the meshes that use it

	// TODO joints

	float minX,minY,minZ;
	float maxX,maxY,maxZ;

public:


	cModel();
	~cModel();

	void Clear();
};







#endif